class Command {
    mapCommand: Map<string, string | Function> = new Map()
    
    // 添加一个AT指令
    addCommand(command: string, fn: Function | string) {
        this.mapCommand.set(command, fn)
    }

    // 删除一个AT指令
    deleteCommand(command: string) {
        if (!this.mapCommand.has(command)) return
        this.mapCommand.delete(command)
    }

    // 获取一个AT指令的值
    getCommand(command: string) {
        if (!this.mapCommand.has(command)) return
        return this.mapCommand.get(command)
    }
}
const command = new Command()

// 1. 添加查询网关
command.addCommand('getGatewayId','AT+CELLID?\r\n')

// 2. 添加查询终端的设备
command.addCommand('getTerminalDeviceList','AT+DEVID?\r\n')

// 3. 添加查询终端的IMEI
command.addCommand('addTerminalDevice',(ESN: string,ID: number) => {
    return `AT+DEV=0,${ESN},3,${ID}\r\n`
})

// 4. 删除终端设备
command.addCommand('deleteTerminalDevice',(ID: number) => {
    return `AT+DEL=1,${ID}\r\n`
})

// 5. 发送协议到终端
command.addCommand('sendProtocol',(ID: number,protocol: string) => {
    return `AT+SEND=${ID},${protocol}\r\n`
})

// 6. 版本号
command.addCommand('getVersion', 'AT+ATCMD=<ID>,<AT+VER?>\r\n')

// 7. 重启设备
command.addCommand('restart', (id: number) => {
    return `AT+ATCMD=<${id}>,<AT+REBOOT>\r\n`
})

// 8. 电脑增益
command.addCommand('setGain', (id: number, gain: number) => {
    return `AT+ATCMD=<${id}>,<AT+GAIN=${gain}>\r\n`
})

// 9. 设备类型
command.addCommand('getDeviceType', (id: number) => {
    return `AT+ATCMD=<${id}>,<AT+DTYPE?>\r\n`
})

export default command